package net.niufei.study.cpatterns.activeobject;

public class ActiveObjectFactory {

	
	public static ActiveObject buildActiveObject() {
		Servant servant = new Servant();
		Scheduler scheduler = new Scheduler(new ActivationQueue(10));
		Proxy proxy = new Proxy(servant, scheduler);
		return proxy;
	}
	
	
	private static class Proxy implements ActiveObject {
		private final Servant servant;
		private final Scheduler scheduler;
		
		public Proxy(Servant servant, Scheduler scheduler) {
			this.servant = servant;
			this.scheduler = scheduler;
		}
		
		@Override
		public Result makeString(int count, char fillChar) {
			FutureResult future = new FutureResult();
			scheduler.invoke(new MakeRequest(servant, future, count, fillChar));
			return future;
		}

		@Override
		public void displayString(String string) {
			scheduler.invoke(new DisplayRequest(servant, string));
		}
		
	}
	
	
}
